const mongoose = require("mongoose")
const fs = require("fs");
const path = require("path")
const MovieSchema = new mongoose.Schema({
    name: String, //电影名
    ename: String, //电影英文名,
    type: String, //电影的类型
    area: String, //电影首映地区
    poster: String, //电影海报
    time: Number, //电影时长（分钟）,
    upDate: String, //电影大陆上映时间,
    score: Number, //电影评分,
    count: String, //电影票房,
    intro: String, //剧情简介,
    isHot: Boolean, //是否正在热映
    isComing: Boolean, //是否即将上映
    isClassic: Boolean, //是否是经典
    director: [{ //导演数组
        name: String, //导演名
        image: String //导演图片
    }],
    actor: [{ //演员数组
        name: String, //演员名
        filmName: String, //饰演名
        image: String //演员图片
    }],
    images: [String] //剧集数组：每一项是一个图片路径字符串
}, {
        versionKey: false,
        timestamps: {
            createdAt: 'createTime',
            updatedAt: 'updateTime'
        } //自动管理修改时间
    })
const movie = mongoose.model("Movie", MovieSchema);
async function addMockjs() {
    const count = await movie.countDocuments();
    if (count == 0) {
        const content = fs.readFileSync(path.join(__dirname, "./data/movie.json")).toString();
        const movies = JSON.parse(content)
        await movie.create(movies)
    }
}
addMockjs();
module.exports = mongoose.model("Movie", MovieSchema);
